package com.tedu07.lcl.mapper;

import com.tedu07.lcl.entity.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {

    @Select("select * from user where uname=#{username}")
    User login(String username);

    @Select("select count(uid) from user where uname=#{uname}")
    int check(String uname);

    @Insert("insert into user values(null,null,#{uname},#{password},0,0,'新用户',null,null,null,null,#{regTime},null,0,0,0,0,null,null)")
    void reg(User user);

    @Select("select uid from user where uname=#{uname}")
    int selectUidByUname(String uname);

    @Update("update user set did=#{did} where uid=#{uid}")
    void updateDidByUid(int did, int uid);

    @Insert("insert into depository values(null,#{uid},0,10485760,null,null)")    //最大容量=10485760KB=10GB
    void createDepository(int uid);

    @Select("select did from depository where uid=#{uid}")
    User selectDidByUid(int uid);

    @Select("select * from user where uid=#{uid}")
    @Result(column = "pic_url",property = "picUrl")
    @Result(column = "reg_time",property = "regTime")
    @Result(column = "last_time",property = "lastTime")
    @Result(column = "transfer_times",property = "transferTimes")
    @Result(column = "transferred_times",property = "transferredTimes")
    @Result(column = "up_times",property = "upTimes")
    @Result(column = "down_times",property = "downTimes")
    User selectAllById(int uid);

    @Update("update user set nick=#{nick},mail=#{mail},birthday=#{birthday},phone=#{phone},pic_url=#{picUrl} where uid=#{uid}" )
    void updateById(User user);

    //修改密码
    @Update("update user set password=#{password} where uid=#{uid}")
    void updatePassword(String password,Integer uid);

}
